﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TempHum.service
{
    class ResizeForm
    {
        public static  void setTag(Control cons)
        {
            Console.WriteLine("setTag");
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
                if (con.Controls.Count > 0) setTag(con);
            }
        }
        public static void setControls(float newx, float newy, Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                string[] mytag = con.Tag.ToString().Split(new char[] { ':' });//3float a = System.Convert.Tosingle(mytag[e]) * newx;//根据窗体缩放比con.Width = (int)a;//宽度
                float a = System.Convert.ToSingle(mytag[0]) * newx;
                con.Width = (int)a;//宽度
                a = System.Convert.ToSingle(mytag[1]) * newy;//高度con.Height = (int)(a);
                con.Height = (int)(a);
                a = System.Convert.ToSingle(mytag[2]) * newx;//左边距con.Left = (int)(a);
                con.Left = (int)(a);
                a = System.Convert.ToSingle(mytag[3]) * newy;//上边缘距离con.Top = (int)(a);
                con.Top = (int)(a);
                Single currentsize = System.Convert.ToSingle(mytag[4]) * newy;//con.Font = new Font(con.Font.Name, currentsize, con.Font.style,c
                con.Font = new Font(con.Font.Name, currentsize, con.Font.Style, con.Font.Unit);
                if (con.Controls.Count > 0)
                {
                    setControls(newx, newy, con);
                }
            }
        }
    }
}
